package LeetCode.tree;

import java.util.*;

public class LC_102 {
    public static List<List<Character>> levelOrder(TreeNode root) {
        List<List<Character>> lists = new LinkedList<>();
        LinkedList<TreeNode> queue = new LinkedList<>();
        if (root == null) {
            return lists;
        }
        queue.offer(root);
        while (!queue.isEmpty()) {
            int size = queue.size();
            List<Character> list = new ArrayList<>();
            while (size != 0) {
                TreeNode cur = queue.poll();
                size--;
                list.add(cur.val);
                if (cur.left != null) {
                    queue.offer(cur.left);
                }
                if (cur.right != null) {
                    queue.offer(cur.right);
                }
            }
            lists.add(list);
        }
        return lists;
    }

    public static void main(String[] args) {

        List<List<Character>> lists = levelOrder(TreeNode.createTree1());
        System.out.println(lists);
    }
}
